const db = require("../lib/db")
// 查询作者列表
function shouyeArticle(){
    return new Promise((resolve,reject)=>{
// 定义查询的sql语句
let sql = "select * from shouyeArticle";
db.querySql(sql).then(data=>{
    if(data.length==0){
        // 返回状态码
        resolve(4004)
    }else{
        // 对数组进行乱序处理
        // let arr = data.sort(()=>0.5-Math.random())
        // console.log(arr)
        let arr2=[]
        data.map(element=>{
            arr2.push({
                _id:Buffer.from(String(element.author_id)).toString("base64"),
                title:element.title,
                content:element.content,
                desc:element.desc1,
                author:element.author,
                authorId:Buffer.from(String(element.authorId)).toString("base64"),
                classify:element.classify
            })
        })
        resolve(arr2)
    }
})
    })
    
}
// 导出
module.exports = shouyeArticle;